package com.meida.module.bus.provider.handler;

import cn.hutool.core.util.ObjectUtil;
import com.meida.common.base.entity.EntityMap;
import com.meida.common.mybatis.interceptor.PageInterceptor;
import com.meida.common.mybatis.model.PageParams;
import com.meida.common.mybatis.query.CriteriaQuery;
import com.meida.module.order.client.entity.OrderInfo;
import com.meida.module.pay.client.entity.PayInfo;
import com.meida.module.pay.provider.service.PayInfoService;
import com.meida.module.user.client.entity.AppUser;
import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;


/**
 * description: 平台商品订单
 * date: 2022年-06月-29日 23:04
 * author: ldd
 */
@Log4j2
@Component
public class BusOrderPageHandler implements PageInterceptor<OrderInfo> {



    @Resource
    private PayInfoService payInfoService;

    @Override
    public void prepare(CriteriaQuery cq, PageParams pageParams, EntityMap params) {
        cq.eq(true, "orderinfo.deleted", 0);
        cq.select(AppUser.class, "userId", "fullName");
        cq.createJoin(AppUser.class);
        cq.select("pi.fromPay", "pi.payDate", "pi.payType", "pi.transactionType");
        cq.createJoin(PayInfo.class).setJoinAlias("pi").setMainField("orderNo").setJoinField("outTradeNo");
        cq.eq(ObjectUtil.isNotNull(params.get("orderType")), "orderinfo.orderType", params.get("orderType"));
        cq.like(ObjectUtil.isNotNull(params.get("userId")), "user.userId", params.get("userId"));
        cq.like(ObjectUtil.isNotNull(params.get("orderTitle")), "orderinfo.orderTitle", params.get("orderTitle"));
        cq.like(ObjectUtil.isNotNull(params.get("fullName")), "user.fullName", params.get("fullName"));
        cq.like(ObjectUtil.isNotNull(params.get("transactionType")), "pi.transactionType", params.get("transactionType"));
        cq.ge(ObjectUtil.isNotEmpty(params.get("beginDate")), "orderinfo.createTime", params.get("beginDate"));
        cq.le(ObjectUtil.isNotEmpty(params.get("endDate")), "orderinfo.createTime", params.get("endDate"));
        cq.ge(ObjectUtil.isNotEmpty(params.get("payBegin")), "pi.payDate", params.get("payBegin"));
        cq.le(ObjectUtil.isNotEmpty(params.get("payEnd")), "pi.payDate", params.get("payEnd"));

        //cq.select(PayInfo.class, "fromPay","payDate", "payType", "transactionType");
        //cq.createJoin(PayInfo.class).setMainField("busId").setJoinField("orderId");
    }

    @Override
    public void complete(CriteriaQuery<OrderInfo> cq, List<EntityMap> result, EntityMap extra) {


    }
}
